﻿



/* ============================== FIELD EDITOR ============================== */




/* ============================== TEMPLATE EDITOR ============================== */



/* ============================== FILE BROWSER ============================== */

var fileBrowserCallers = new Array();
function BrowseToFile(targetElId, fileType) {
    var callerNo = fileBrowserCallers.length;
    fileBrowserCallers[callerNo] = targetElId;

    OpenDialog("/limestone/filebrowser?caller=custom&type=" + fileType + "&CKEditorFuncNum=" + callerNo);
}

function onFileBrowseComplete(callerNo, path) {
    $('#' + fileBrowserCallers[callerNo]).val(path);
}

/* ============================== PAGE BROWSER ============================== */

var pageBrowserCallers = new Array();
function BrowseToPage(targetElId) {
    var callerNo = pageBrowserCallers.length;
    pageBrowserCallers[callerNo] = targetElId;

    OpenDialog("/limestone/PageBrowser?callerNo=" + callerNo);
}

function onPageBrowseComplete(callerNo, path) {
    $('#' + pageBrowserCallers[callerNo]).val(path);
}


/* ============================== DIALOG ============================== */

function OpenDialog(url, width, height) {
    width = width || '80%';
    height = height || '70%';
    if (typeof width == 'string' && width.length > 1 && width.substr(width.length - 1, 1) == '%')
        width = parseInt(window.screen.width * parseInt(width, 10) / 100, 10);
    if (typeof height == 'string' && height.length > 1 && height.substr(height.length - 1, 1) == '%')
        height = parseInt(window.screen.height * parseInt(height, 10) / 100, 10);
    if (width < 640)
        width = 640;
    if (height < 420)
        height = 420;
    var top = parseInt((window.screen.height - height) / 2, 10);
    var left = parseInt((window.screen.width - width) / 2, 10);
    var settings = 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left;
    var dialog = window.open('', null, settings, true);
    if (!dialog)
        return false;
    try {
        dialog.moveTo(top, left);
        dialog.resizeTo(width, height);
        dialog.focus();
        dialog.location.href = url;
    }
    catch (s) {
        dialog = window.open(url, null, settings, true);
    }
    return true;
}